export default {
  data() {
    return {
      current_page: 0,
      status: 'loadmore',
      total: 0,
      isRefreshing: false,
      isOnce: true,
      tableData: [],
      statusBarHeight: 0,
    };
  },
  mounted() {
    this.statusBarHeight = uni.getWindowInfo().statusBarHeight;

    /* #ifdef MP */
    if (this.statusBarHeight == 0){
      this.statusBarHeight = uni.getMenuButtonBoundingClientRect().top;
    }
      
    /* #endif */
  },
  methods: {
    menuButtonInfo() {
      let menuButtonInfo = 0;
      let titleBarHeight = 0;
      let statusBarHeight = 0;
      let safeAreaInsetsBottom = 0;
      let top = 0;
      let res = uni.getWindowInfo();
      try {
        menuButtonInfo = uni.getMenuButtonBoundingClientRect();
        statusBarHeight = res.statusBarHeight || menuButtonInfo.top;
        safeAreaInsetsBottom =
          res.screenHeight - res.safeArea.height - res.statusBarHeight;
        statusBarWidth = menuButtonInfo.width;
        titleBarHeight =
          (menuButtonInfo.top - res.statusBarHeight) * 2 +
          menuButtonInfo.height;
      } catch (error) {}
      let data = {
        statusBarHeight: statusBarHeight,
        safeAreaTop: res.safeArea.top,
        titleBarHeight: titleBarHeight,
        top: statusBarHeight + titleBarHeight,
        bottom: safeAreaInsetsBottom,
        topBottom: top + safeAreaInsetsBottom,
      };
      return data;
    },
    handleClear() {},
    searchTap() {
      this.current_page = 0;
      this.$set(this.form, 'page', 1);
      this.initPage(() => {
        this.tableData = [];
      });
    },
    tabTap(value) {
      this.current_page = 0;
      this.$set(this.form, 'page', 1);
      this.$set(this.form, 'sort', value.sort);
      this.$nextTick(() => {
        this.initPage(() => {
          this.tableData = [];
        });
      });
    },
    onReachBottom() {
      if (this.total > this.tableData.length) {
        this.status = 'loading';
        let page = this.form.page;
        this.$set(this.form, 'page', page + 1);
        this.initPage();
      } else {
        this.status = 'nomore';
      }
    },
    bindrefresherrefresh() {
      this.current_page = 0;
      this.$set(this.form, 'page', 1);
      this.isRefreshing = true;
      this.initPage(() => {
        this.tableData = [];
      });
    },
    onRefresherRestore() {
      this.isRefreshing = false;
    },
  },
};
